<!-- This is a test to ensure that drawing buffer creation failure gracefully fails WebGL context creation -->
<script src="../../resources/js-test.js"></script>
<canvas id="webgl-canvas" width="200" height="200" class="nomargin"></canvas>
<script>
function main()
{
  if (!window.testRunner) {
    testFailed("Requires window.testRunner");
  } else {
    initTest();
  }
}

function initTest() {
  var canvas = document.getElementById("webgl-canvas");
  testRunner.forceNextDrawingBufferCreationToFail();
  canvas.addEventListener("webglcontextcreationerror", onContextCreationError, false);
  var gl = canvas.getContext("webgl");
  if (gl)
    testFailed("Context creation should not have succeeded.");
  testRunner.dumpAsText();
}

function onContextCreationError(e) {
  var splitStatus = e.statusMessage.split(",");
  var stringLocator = 1;
  var status = true;
  // Start iterating from 1 as , the initial message has no data.
  for (var i = 1; i < splitStatus.length; i++) {
    var gpuInfoStr = splitStatus[i].split(" = ");
    if (gpuInfoStr[stringLocator] == "")
      status = false;
  }
  if(status)
    testPassed("Status message displayed for webglcontextcreationerror");
  else
    testFailed("Context creation error test failed");
}
main();
</script>
